#include"Rectangles.h"
Rectangles::Rectangles() : Object()
{
	this->m_RectWidth = 1;
	this->m_RectWidth = 1;
	SetType(RECTANGLE);
}
Rectangles::Rectangles(float posX, float posY, int m_Width, int m_Height) : Object(posX, posY) 
{
	this->m_RectWidth = m_Width;
	this->m_RectHeight = m_Height;
	SetType(RECTANGLE);
}
Rectangles::~Rectangles()
{
	//cout<<"Destructor Rectangle"<<endl;
}
void Rectangles::Render()
{
	//	DrawFullLine(); 
	VideoDriver::GetInstance()->DrawRect((int)m_PositionX, (int)m_PositionY, m_RectWidth, m_RectHeight);
}
void Rectangles::SetWidth(int m_Width)
{
	this->m_RectWidth = m_Width;
}
void Rectangles::SetHeigth(int m_Height)
{
	this->m_RectHeight = m_Height;
}
int Rectangles::GetHeight()
{
	return this->m_RectHeight;
}
int Rectangles::GetWidth()
{
	return this->m_RectWidth;
}
void Rectangles::Update(float frameTime)
{

}
bool Rectangles::InRect(int posX, int posY)
{
	if(posX >= this->m_PositionX && posX <= (this->m_PositionX + this->m_RectWidth)
		&& posY >= this->m_PositionY && posY <=(this->m_PositionY + this->m_RectHeight))
		return true;
	else return false;

}
//Task 3
int Rectangles::CheckCollisionWithEdge()
{
	int result = 0;
	if(this->m_PositionX <= 0)
		result |= LEFT;
	else if(this->m_PositionX >= (int)SCREEN_W - this->m_RectWidth)
		result |= RIGHT;
	if(this->m_PositionY <= 0)
		result |= TOP;
	else if(this->m_PositionY >= (int)SCREEN_H - this->m_RectHeight)
		result |= BOTTOM;
	return result;

}

bool Rectangles::HasCollisionWithObject(Object *object)
{
	int type = object->GetType();
	if(type == RECTANGLE)
		return HasCollisionWithRect((Rectangles*)object);
	else if(type == CIRCLE)
		return object->HasCollisionWithObject(this);
	else return false;
}
bool Rectangles::HasCollisionWithRect(Rectangles *rect)
{
	if(this->m_PositionX > rect->m_PositionX + rect->m_RectWidth  
		|| this->m_PositionY > rect->m_PositionY + rect->m_RectHeight
		|| rect->m_PositionX < this->m_PositionX + this->m_RectWidth
		|| rect->m_PositionY > this->m_PositionX + this->m_RectWidth)
		return false;
	else return true;
}